package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.MaintenanceCostDao;
import cn.topevery.garden.entity.po.MaintenanceCost;
import cn.topevery.garden.entity.query.MaintenanceCostQuery;
import cn.topevery.garden.entity.vo.MaintenanceCostVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 保养费用记录
 *
 * @author code-generate
 * @date 2022-02-17
 */
@Repository
public class MaintenanceCostDaoImpl extends BaseDaoImpl<MaintenanceCost> implements MaintenanceCostDao {
    @Override
    public <P extends DbCsp> List<MaintenanceCost> getSearch(P para) {
        return null;
    }



    @Override
    public DataPager<MaintenanceCostVO> listPage(MaintenanceCostQuery query) {
        String table = "t_maintenance_cost tmc left join t_maintenance_record tmr on tmc.c_maintenance_id=tmr.c_id";

        String columns = "tmc.*, tmr.c_record_code recordCode";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tmc.c_id desc");
        sqlQueryMate
                .where(true, "tmc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getRecordCode()), "tmr.c_record_code", ScriptConditionEnum.Like, query.getRecordCode())
                .where(StringUtils.isNotBlank(query.getName()), "tmc.c_name", ScriptConditionEnum.Like, query.getName())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, MaintenanceCostVO.class);
    }

    @Override
    public MaintenanceCost getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
